<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo  Q::ini('appini/app_title')." ". Q::ini('appini/version');?></title>
<link href="css/default.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="js/jquery-easyui/themes/default/easyui.css"/>
<link rel="stylesheet" type="text/css" href="js/jquery-easyui/themes/icon.css"/>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery-easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="js/jquery-easyui/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>

<script language="javascript">
function newagent(){  
    $('#dlg').dialog('open').dialog('setTitle','添加代理');  
    $('#fm').form('clear');  
    url = '<?=url("agent/new")?>';  
} 

function editagent(){
	var row = $('#dg').datagrid('getSelected');  
    if (row){  
        $('#dlg').dialog('open').dialog('setTitle','编辑代理');  
        $('#fm').form('load',row);  
		url = '<?=url("agent/update")?>';
    } 
	else{
		$.messager.show({
			'title': "提示",
			'msg': "请选择要编辑的记录."	
		});	
	} 		
}

function saveagent(){  
	$('#fm').form('submit',{  
		url: url,  
		onSubmit: function(){  
			return $(this).form('validate');  
		},  
		success: function(result){  
			var result = eval('('+result+')');  
			if (result.errorMsg){  
				$.messager.show({  
					title: '出错了',  
					msg: result.errorMsg  
				});  
			} else {  
				$('#dlg').dialog('close');      // close the dialog  
				$('#dg').datagrid('reload');    // reload the user data  
			}  
		}  
	});  
}  

function destroyagent(){  
    var row = $('#dg').datagrid('getSelected');  
    if (row){  
        $.messager.confirm('确认','您确认要删除该记录吗?',function(r){  
            if (r){  
                $.post('<?=url("agent/destroy")?>',{id:row.agent_id},function(result){  
                    if (result.success){  
                        $('#dg').datagrid('reload');    // reload the user data  
                    } else {  
                        $.messager.show({   // show error message  
                            title: '出错了',  
                            msg: result.errorMsg  
                        });  
                    }  
                },'json');  
            }  
        });  
    }
	else{
		$.messager.show({   // show error message  
			title: '提示',  
			msg: "请选择要删除的记录."
		});  	
	}  
}

function searchagent(){  
    $('#dlgSearch').dialog('open').dialog('setTitle','查找');  
}

function doSearch(){
	key=$("#key").val()
	op=$("#op").val();
	value=$("#value").val();
	$("#dg").datagrid({ url: '<?=url('agent/list')?>', queryParams: { key: key,op:op,value:value} });
	
	$('#dlgSearch').dialog('close');
} 
</script>
</head>

<body class="easyui-layout" style="overflow-y: hidden" scroll="no">
    
    <div region="center" style="width: 500px; height: 300px; padding: 1px;overflow-y: hidden">
        <table id="dg" title="代理管理"  class="easyui-datagrid" url="<?=url("agent/list")?>"  toolbar="#toolbar"  rownumbers="true" fitColumns="true" singleSelect="true" iconCls="icon-save"  pagination="true" fit="true">  
        	<thead>  
                <tr>  
                    <th field="name" width="50">代理名称</th>
                    <th field="site" width="50">站点</th>                     
                </tr>  
        	</thead>  
    	</table>  
    	<div id="toolbar">  
            <a href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="newagent()">新增</a> | 
            <a href="#" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="editagent()">编辑</a> |  
            <a href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="destroyagent()">删除</a> |  
            <a href="#" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="searchagent()">查找</a>
    	</div>  
    </div>
	<div id="dlg" class="easyui-dialog" style="width:450px;height:300px;padding:10px 20px" closed="true" buttons="#dlg-buttons"  modal="true">  
        <div class="ftitle">详细信息</div>  
        <form id="fm" method="post">  
            <table width="100%" border="0" cellspacing="1" cellpadding="2">
              <tr>
                <td height="25" align="right"><span class="fitem">
                  <label>代理名称:</label>
                </span></td>
                <td align="left">
                <input name="name" id="name" class="easyui-validatebox" required="true" />
                </td>
              </tr>
              <tr>
                <td height="25" align="right"><span class="fitem">
                  <label>站点:</label>
                </span></td>
                <td align="left">
                <select name="site_id" id="site_id" class="easyui-combogrid" data-options="  
            panelWidth:350,            
            idField:'site_id',  
            textField:'name',  
            url:'<?=url("site/list")?>',  
            columns:[[  
                {field:'site_id',title:'编号',width:60},  
                {field:'name',title:'名称',width:280}  
            ]]">
                  </select>
                </td>
              </tr>
            </table>           
              <input name="agent_id" id="agent_id" type="hidden"  />          
        </form>  
    </div>  
    <div id="dlg-buttons">  
        <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="saveagent()">保存</a>  
        <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')">取消</a>  
    </div>   
    
    <!--search box-->
    <div id="dlgSearch" class="easyui-dialog" style="width:400px;height:200px;padding:10px 20px" closed="true" buttons="#dlgSearch-buttons"  modal="true"> 
    <form method="post">
    <select name="key" id="key" class="easyui-validatebox" required="true" >
    <option value="name">代理名称</option>
    </select>
    <select name="op" id="op" class="easyui-validatebox" required="true" >
    <option value="=">等于</option>
    <option value=">">大于</option>
    <option value="<">小于</option>
    <option value="like">包含</option>
    </select>
    <input name="value" id="value" type="text" class="easyui-validatebox" required="true" />
    </form>
    </div>
    <div id="dlgSearch-buttons">  
        <a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="doSearch()">查找</a>  
        <a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlgSearch').dialog('close')">取消</a>  
    </div>  
        
</body>
</html>